<!--
  Copyright 2017-2018 the original author or authors.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<div class="gt-header">
  <div class="gt-header-lhs"
       ng-if="!layout.embeddedAgentRollup.display">
    <h1 class="gt-header-text">
      Incidents
    </h1>
  </div>
  <div class="gt-header-lhs"
       ng-if="layout.embeddedAgentRollup.display">
    <div class="gt-header-text">
      {{layout.embeddedAgentRollup.display}}
    </div>
    <!-- don't use border to simulate vertical bar since this will jitter on reload (at least in Chrome)
         while chrome guesses the placement of the border based on default font and then it moves slightly
         once font is available -->
    <div class="gt-header-text gt-separator">
      |
    </div>
    <h1 class="gt-header-text">
      Incidents
    </h1>
  </div>
</div>

<div class="card gt-incident-active">
  <div class="card-header">
    <h2>Open</h2>
  </div>
  <div class="card-body">
    <div ng-include src="'template/gt-loading-overlay.html'"></div>
    <div ng-include src="'template/gt-http-error-overlay.html'"></div>
    <div style="margin: 15px;">
      <table class="table"
             style="table-layout: fixed;">
        <thead>
        <th scope="col" style="width: 105px;">Severity</th>
        <th scope="col" style="width: 110px;">Duration</th>
        <th scope="col" style="width: 180px;" ng-if="layout.central">Agent</th>
        <th scope="col">Condition</th>
        </thead>
        <tbody>
        <tr ng-repeat="incident in openIncidents"
            class="gt-red"
            style="font-weight: 600; font-size: 1rem;">
          <td>{{incident.severity}}</td>
          <td>{{incident.durationMillis | gtDuration}}</td>
          <td ng-if="layout.central">{{incident.agentRollupDisplay}}</td>
          <td>
            <a ng-if="incident.href" ng-href="{{incident.href}}">{{incident.display}}</a>
            <span ng-if="!incident.href">{{incident.display}}</span>
          </td>
        </tr>
        </tbody>
      </table>
    </div>
  </div>
</div>

<div class="card"
     ng-if="loaded"
     style="margin-top: 50px;">
  <div class="card-header">
    <h2>Resolved
      <div style="float: right; padding-top: 10px; font-size: 24px;">(last 30 days)</div>
    </h2>
  </div>
  <div class="card-body">
    <div ng-include src="'template/gt-http-error-overlay.html'"></div>
    <div style="margin: 15px;">
      <table class="table"
             style="table-layout: fixed;">
        <thead>
        <th scope="col" style="width: 105px;">Severity</th>
        <th scope="col" style="width: 220px;">Resolved</th>
        <th scope="col" style="width: 110px;">Duration</th>
        <th scope="col" style="width: 180px;" ng-if="layout.central">Agent</th>
        <th scope="col">Condition</th>
        </thead>
        <tbody>
        <tr ng-repeat="incident in resolvedIncidents"
            style="font-size: 1rem;">
          <td>{{incident.severity}}</td>
          <td>{{incident.resolveTime | date:'medium'}}</td>
          <td>{{incident.durationMillis | gtDuration}}</td>
          <td ng-if="layout.central">{{incident.agentRollupDisplay}}</td>
          <td>
            <a ng-if="incident.href" ng-href="{{incident.href}}">{{incident.display}}</a>
            <span ng-if="!incident.href">{{incident.display}}</span>
          </td>
        </tr>
        </tbody>
      </table>
    </div>
  </div>
</div>
